﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Table = FCNS.Data.Table;
using DoubleH.Utility;

namespace POS
{
    /// <summary>
    /// WindowStopSale.xaml 的交互逻辑
    /// </summary>
    public partial class WindowStopSale : Window
    {
        public WindowStopSale()
        {
            InitializeComponent();
        }

        string obj;
        string arg;
        public void Init(string arg, string obj)
        {
            this.obj = obj;
            this.arg = arg;

            InitVar();
            InitEvent();
        }

        private void InitEvent()
        {
            buttonSave.Click += (ss, ee) =>
                {
                    if (checkListBoxPos.SelectedItems.Count == 0)
                        return;

                    switch (arg)
                    {
                        case "p": FCNS.Data.SQLdata.ExecuteNonQuery("update ProductS set PosCanNotUse='" + checkListBoxPos.SelectedValue + "' where Id=" + obj); break;
                        case "u": FCNS.Data.SQLdata.ExecuteNonQuery("update PosS set UserList='" + checkListBoxPos.SelectedValue + "' where PosNO like '" + obj + "'"); break;
                    }
                    this.Close();
                };
        }

        private void InitVar()
        {
            switch (arg)
            {
                case "p":
                    checkListBoxPos.DisplayMemberPath = "PosNO";
                    checkListBoxPos.ValueMemberPath = "PosNO";
                    checkListBoxPos.ItemsSource = Table.PosS.GetList(Table.PosS.EnumEnable.启用);
                    break;

                case "u":
                    this.Title = "收银员编辑";
                    groupBox1.Header = "收银员列表";
                    checkListBoxPos.DisplayMemberPath = "Name";
                    checkListBoxPos.ValueMemberPath = "Id";
                    checkListBoxPos.ItemsSource = Table.UserS.GetList(Table.UserS.EnumEnable.启用, Table.UserS.EnumFlag.POS操作员);

                    Table.PosS pos = Table.PosS.GetObject(obj);
                    if (pos._UserList == null)
                        return;

                    foreach (Table.UserS us in pos._UserList)
                        foreach (object oo in checkListBoxPos.Items)
                            if (((Table.UserS)oo).Id == us.Id)
                                checkListBoxPos.SelectedItems.Add(oo);

                    break;

            }
        }
    }
}